﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Windows.Input;

namespace TiaoTiaoCode.AutoUpdate.ServerUI.ViewModels
{
    public class LoginViewModel : BindableBase, IDialogAware
    {
        #region 属性

        private string loginName = default!;

        /// <summary>
        /// 用户名
        /// </summary>
        public string LoginName
        {
            get { return loginName; }
            set { SetProperty(ref loginName, value); }
        }

        #endregion

        #region 命令

        ICommand? loginCommand;

        /// <summary>
        /// 用户登录
        /// </summary>
        public ICommand LoginCommand => loginCommand ?? (loginCommand = new DelegateCommand(Login));        

        #endregion

        public LoginViewModel()
        {

        }

        #region 命令实现

        void Login()
        {
            RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
        }

        #endregion

        #region Dialog接口实现

        public string Title => "登录";

        public event Action<IDialogResult>? RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {

        }

        public void OnDialogOpened(IDialogParameters parameters)
        {

        }

        #endregion
    }
}
